<?php

// @formatter:off
/**
 * @file WCParserBehavior.php
 *
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: WCParserBehavior.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/includes/parser/WCParserBehavior.php $
 */
// @formatter:on

/**
 * @abstract
 * @class WCParserBehavior This is an abstract representation of a parser node's
 * behavior (a.k.a. function handler).
 */
abstract class WCParserBehavior {
	/**
	 * @var WCParserNode Node to which this behavior is attached to.
	 */
	protected $_node = false;
	/**
	 * @var boolean Current status.
	 */
	protected $_ok = false;
	/**
	 * @var string Last error message.
	 */
	protected $_errorMsg = "Unknown error";
	/**
	 * @var WCParser Pointer to the parser where this behavior is attached to.
	 */
	protected $_parser = null;
	/**
	 * Class constructor.
	 *
	 * @param WCParserNode $node Pointer to the node to which this behavior
	 * will be attached to.
	 */
	public function __construct(WCParserNode &$node) {
		//
		// Saving node's pointer.
		$this->_node = $node;
		//
		// Saving node's parser pointer.
		$this->_parser = $this->_node->parser();
		//
		// Triggering the class initializer.
		$this->init();
	}
	//
	// Public methods.
	/**
	 * @abstract
	 * This is an abstract method and it must perform a check of the object,
	 * set the current status (variable $this->_ok) and return that status.
	 *
	 * @warning Subclass Responsibility
	 *
	 * @return boolean Returns the current status after a check.
	 */
	public function check() {
		trigger_error("Subclass Responsibility", E_USER_ERROR);
		return $this->isOk();
	}
	/**
	 * This method returns the last error message reported by this behavior.
	 *
	 * @return string Returns the last error message.
	 */
	public function errorMessage() {
		return $this->_errorMsg;
	}
	/**
	 * This method allows to get the current status of this behavior.
	 *
	 * @return boolean Returns current status.
	 */
	public function isOk() {
		return $this->_ok;
	}
	/**
	 * @abstract
	 * This is an abstract method and it must parse parameters and contents of
	 * the node and generates a text based on them.
	 *
	 * @warning Subclass Responsibility
	 *
	 * @return string Returns the resulting string or false in case of errors.
	 */
	public function get() {
		trigger_error("Subclass Responsibility", E_USER_ERROR);
		return false;
	}
	//
	// Protected methods.
	/**
	 * This method is a generic initializer called by every constructor. By
	 * default it does nothing unless it is inherited and redefined.
	 */
	protected function init() {
		
	}
}
